#!/usr/bin/python
# -*- coding: utf-8 -*-

def find_image(image_name):
    """Using the iamge_name, search in the common places. Return the path for
    the image or None if the image couldn't be found."""

    import os
    import os.path
    import sys

    # the order is the priority, so keep global paths before local paths

    current_dir = os.path.abspath(os.path.dirname(__file__))

    common_paths = [
            os.path.join(sys.prefix, 'share', 'pixmaps'),
            os.path.join('.', 'pixmaps'),
            os.path.join(current_dir, '..', 'pixmaps')
            ]

    for path in common_paths:
        filename = os.path.join(path, image_name)
        if os.access(filename, os.F_OK):
            return filename

    return None

